package com.isoftstone.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.isoftstone.wms.entity.User;
import com.isoftstone.wms.mapper.UserMapper;
import com.isoftstone.wms.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wms
 * @since 2025-09-30
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public boolean isAccountExists(User user) {
        if (StringUtils.isBlank(user.getNo())) {
            return false;
        }
        
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getNo, user.getNo());
        // 如果是编辑用户，排除当前用户
        if (user.getId() != null) {
            wrapper.ne(User::getId, user.getId());
        }
        
        return this.count(wrapper) > 0;
    }
}
